<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="__PUBLIC__/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/css/style.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/lib/Hui-iconfont/1.0.6/iconfont.css" rel="stylesheet" type="text/css" />
<link href="/Tpl/Admin/common/role/role.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>管理员列表</title>
</head>
<body>
<div class="pd-20">
	<form action="" method="post" class="form form-horizontal" id="form-user-character-add">
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>角色名称：</label>
			<div class="formControls col-10">
				<input type="text" class="input-text" value="" placeholder="" id="name111" name="name" datatype="*" nullmsg="用户账户不能为空">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2">描述：</label>
			<div class="formControls col-10">
				<input type="text" class="input-text remark" value="" placeholder="" id="" name="remark">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2">是否启用：</label>
			<div class="formControls col-10">
				<input type="checkbox" class="status" value="1" placeholder="" id="" name="status" checked="checked">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2">网站角色：</label>
			<div class="formControls col-10">
				<volist name="node" id="vo">
					<dl class="permission-list">
							<dt>
								<label><input type="checkbox" value="{$vo.id}" name="user-Character-0" id="user-Character-1">{$vo.title}</label>
							</dt>
							<dd>
								<dl class="cl permission-list2">
									<volist name="vo['child']" id="ko">
									<dt style="width: 110px;">
										<label class="">
											<input type="checkbox" value="{$ko.id}" name="user-Character-1-0" id="user-Character-1-0">
											{$ko.title}</label>
									</dt>
									</volist>
								</dl>
							</dd>
					</dl>
				</volist>
			</div>
		</div>
		<div class="row cl">
			<div class="col-10 col-offset-2">
				<!-- <button  class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button> -->
				<span class="btn btn-success radius" id="admin-role-save"><i class="icon-ok"></i>确定</span>
			</div>
		</div>
	</form>
</div>
<script type="text/javascript" src="__PUBLIC__/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/layer/2.1/layer.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/laypage/1.2/laypage.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/My97DatePicker/WdatePicker.js"></script> 
<script type="text/javascript" src="__PUBLIC__/js/H-ui.js"></script> 
<script type="text/javascript" src="__PUBLIC__/js/H-ui.admin.js"></script> 
<script>
$(function(){

	var nodes=[];

	$(document).on("click","#admin-role-save",function(){
		$(".permission-list input:checked").each(function(){
			nodes.push($(this).val());
		});
		var name=$("#name111").val();
		var status=$(".status:checked").val();
		if(status==null){
			status=0;
		}
		console.log(status);
		var remark=$(".remark").val();
		addData(name,status,remark);
	});

	function addData(name,status,remark){
		$.post("/index.php?m=Admin&c=Role&a=add&",{nodes:nodes.toString(),name:name,status:status,remark:remark},function(){
			layer.msg("添加成功");
                var index = parent.layer.getFrameIndex(window.name);
                setTimeout(function(){
                       parent.layer.close(index);
                },1000);
                 parent.location.reload();
		});
	}




	$(".permission-list dt input:checkbox").click(function(){
		$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
	});
	$(".permission-list2 dd input:checkbox").click(function(){
		var l =$(this).parent().parent().find("input:checked").length;
		var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
		if($(this).prop("checked")){
			$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
			$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
		}
		else{
			if(l==0){
				$(this).closest("dl").find("dt input:checkbox").prop("checked",false);
			}
			if(l2==0){
				$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
			}
		}
		
	});

// 当点击子权限时，查找子权限中是否有选中的，若true则父权限为选中，反之亦然
	$(".permission-list2 input:checkbox").click(function(){

		var l=$(this).closest('dl').find('input:checked').length;
		if(l!==0){
			$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
		}else{
			$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
		}


	});
});
</script>
</body>
</html>